<?php

namespace Xuan\Controller;

class ServiceController extends CommonController {

    public function lists() {
        $sql = "1=1 AND pid >0";
        $count = M('service')->where($sql)->count();    //计算总数
        $Page = new \Think\Page($count, C("pagenum"));
        $lists = M('service')->where($sql)->limit($Page->firstRow . ',' . $Page->listRows)->order('ord ASC,id desc')->select();
        $page = $Page->show();
        $this->assign("page", $page);
        $this->assign("lists", $lists);
        $this->display();
    }

    public function detail() {
        $id = I('get.id', '', 'int');
        $detail = M('service')->where("id = " . $id . "")->find();
        $cats = M('service')->where("pid = 0")->select();
        $this->assign("cats", $cats);
        $this->assign("detail", $detail);
        $this->display();
    }

    public function detail_post() {
        $id = I('post.id', '', 'int');
        $data['name'] = I('post.name');
        $data['num'] = I("post.num");
        $data['ord'] = I('post.ord');
        $data['pid'] = I("post.pid");
        if ($id > 0) {
            M('service')->where("id = " . $id . "")->save($data);
            $this->success('修改成功！', U('Service/lists'));
        } else {
            M('service')->add($data);
            $this->success('添加成功！', U('Service/lists'));
        }
    }

    public function cat() {
        $sql = "1=1 AND pid = 0";
        $count = M('service')->where($sql)->count();    //计算总数
        $Page = new \Think\Page($count, C("pagenum"));
        $lists = M('service')->where($sql)->limit($Page->firstRow . ',' . $Page->listRows)->order('ord ASC')->select();
        $page = $Page->show();
        $this->assign("page", $page);
        $this->assign("lists", $lists);
        $this->display();
    }

    public function cat_detail() {
        $id = I('get.id', '', 'int');
        $detail = M("service")->where("id = " . $id . "")->find();
        $this->assign("detail", $detail);
        $this->display();
    }

    public function cat_detail_post() {
        $id = I('post.id', '', 'int');
        $data['name'] = I('post.name');
        $data['ord'] = I('post.ord');
        if ($id > 0) {
            M("service")->where("id = " . $id . "")->save($data);
            $this->success('修改成功！', U('Service/cat'));
        } else {
            M("service")->add($data);
            $this->success('添加成功！', U('Service/cat'));
        }
        clearTempFile();
    }

    public function modal_post() {
        $data['is_start_service'] = I('post.is_start_service');
        M("config")->where("id = 1")->save($data);
        clearTempFile();
        $this->success('修改成功！', U('Service/modals') . "");
    }

}

?>
